﻿#include "framework.h"
#include <QLayout>
#include <QLabel>
#include <QPushButton>

Framework::Framework()
{

    initControl();
}

void Framework::setMainWidget(QWidget *mainWidget)
{
    //只能设置一个主窗体
    //if(this->mainWidget==0){
        this->widget->layout()->addWidget(mainWidget);  //将子窗体添加到布局
        resize(mainWidget->width(),mainWidget->height()+this->widgetTitle->height());   //自动设置大小
        this->mainWidget=mainWidget;
    //}
}

void Framework::initControl()
{
    //纵向布局，上方标题栏，下方widgetMain
    QVBoxLayout *verticalLayout1;
    verticalLayout1 = new QVBoxLayout(this);
    verticalLayout1->setMargin(0);
    verticalLayout1->setSpacing(0);

    QWidget *widgetTitle = new QWidget(this);
    widgetTitle->setMinimumSize(QSize(0, 30));//标题栏高度30
    widgetTitle->setMaximumSize(QSize(16777215,30));

    verticalLayout1->addWidget(widgetTitle);

    //上方标题栏。水平布局（widgetTitle的布局），从左至右:logo+title+skin+min+max+close
    QHBoxLayout *horizontalLayout4=new QHBoxLayout(widgetTitle);
    horizontalLayout4->setSpacing(0);
    horizontalLayout4->setMargin(0);
    QLabel *labIco=new QLabel(widgetTitle);

    labIco->setMinimumSize(QSize(30,0));        //宽30，高由widgetTitle高确定
    labIco->setMaximumSize(QSize(30,16777215));
    labIco->setAlignment(Qt::AlignCenter);
    labIco->setFrameShape(QFrame::Box);
    labIco->setText("Logo");

    QLabel *labTitle=new QLabel(widgetTitle);   //宽高由其他确定
    labTitle->setAlignment(Qt::AlignCenter);
    labTitle->setFrameShape(QFrame::Box);
    labTitle->setText("This is title");

    horizontalLayout4->addWidget(labIco);       //logo
    horizontalLayout4->addWidget(labTitle);     //title

    QWidget *widgetMenu=new QWidget(widgetTitle);
    widgetMenu->setMinimumSize(QSize(30,0));
    widgetMenu->setMaximumSize(QSize(30,16777215));

    QPushButton *btnMenu=new QPushButton(widgetTitle);
    btnMenu->setMinimumSize(QSize(30,0));
    btnMenu->setMaximumSize(QSize(30,16777215));

    QPushButton *btnMenu_Min=new QPushButton(widgetTitle);
    btnMenu_Min->setMinimumSize(QSize(30,0));
    btnMenu_Min->setMaximumSize(QSize(30,16777215));

    QPushButton *btnMenu_Max=new QPushButton(widgetTitle);
    btnMenu_Max->setMinimumSize(QSize(30,0));
    btnMenu_Max->setMaximumSize(QSize(30,16777215));

    QPushButton *btnMenu_Close=new QPushButton(widgetTitle);
    btnMenu_Close->setMinimumSize(QSize(30,0));
    btnMenu_Close->setMaximumSize(QSize(30,16777215));

    horizontalLayout4->addWidget(btnMenu);          //skin
    horizontalLayout4->addWidget(btnMenu_Min);      //min
    horizontalLayout4->addWidget(btnMenu_Max);      //max
    horizontalLayout4->addWidget(btnMenu_Close);    //close

    //下方widgetMain
    //mainWidget = new QWidget(this);
    verticalLayout1->addWidget(mainWidget);
}
